package com.chj.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.chj.dao.ParkDAO;
import com.chj.entity.Park;
import com.chj.mapper.ParkMapper;
import com.etc.jdbc.util.JDBCUtils;

@Repository
public class ParkDAOImpl implements ParkDAO {

    @Override
    public List<Park> getParkListByNetWorkId(String netWorkId) {

        String sql = " select * from t_park T where T.network_id = ? ";

        return JDBCUtils.queryForList(sql, new ParkMapper(), netWorkId);
    }

    public boolean isParkExist(String parkId){

        String sql = " select * from t_park T where T.park_id = ? ";

        if (JDBCUtils.queryForInt(sql, parkId) > 0){

            return true;
        } else {

            return false;
        }
    }

    @Override
    public int save(Park park) {

        String sql = "INSERT INTO `t_park` (`park_id`, `park_name`, `park_size`, `park_price`, `park_type`, `park_status`, `network_id`, `create_date`, `modify_date`, `delete_date`, `status`)";
        sql += " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

        int i = JDBCUtils.update(sql
                               , park.getParkId()
                               , park.getParkName()
                               , park.getParkSize()
                               , park.getParkPrice()
                               , park.getParkType()
                               , park.getParkStatus()
                               , park.getNetworkId()
                               , park.getCreateDate()
                               , park.getModifyDate()
                               , park.getDeleteDate()
                               , park.getStatus()
                               );

        return i;
    }

    @Override
    public List<Park> getParkListByNetWorkId(String netWorkId, int page,int rows) {
        String sql = " select * from t_park T where T.network_id = ? LIMIT ?,? ";

        return JDBCUtils.queryForList(sql, new ParkMapper(), netWorkId, ((page-1)*rows),((page)*rows));
    }

    @Override
    public int delete(Park park) {

        String sql = " delete from t_park where park_id = ? ";

        return JDBCUtils.update(sql, park.getParkId());
    }

    @Override
    public int update(Park park) {

        String sql = "UPDATE `t_park` SET `park_name`= ?, `park_size`= ? , `park_price`= ? WHERE (`park_id`= ? )";

        return JDBCUtils.update(sql, park.getParkName(), park.getParkSize(), park.getParkPrice(), park.getParkId());
    }

    @Override
    public Park get(String parkId) {

        String sql = "select * from t_park where park_id = ?";

        return JDBCUtils.queryForObject(sql, new ParkMapper(), parkId);
    }
}
